import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:web_socket_channel/io.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:xianyu_school/utils/Screen.dart';
import 'package:xianyu_school/xianyuApp/mine/Widgets/mineNavibar.dart';
import 'package:xianyu_school/xianyuApp/mine/Widgets/mineHeader.dart';
import 'package:xianyu_school/xianyuApp/mine/Widgets/mineSell.dart';
import 'package:xianyu_school/xianyuApp/mine/Widgets/mineBuy.dart';

class minePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _minePageState();
  }
}

class _minePageState extends State<minePage> {//保留状态在点击按钮时不会重新运行build方法

  double naviAlpha = 0;
  ScrollController _scrollController;//滚动监听

  @override
  bool get wantKeepAlive => true;//AutomaticKeepAliveClientMixin自带

  @override
  void initState() {
    super.initState();
    _scrollController = ScrollController();
    _scrollController.addListener(() {
      var offset = _scrollController.offset;
      if (offset < 0) {
        setState(() {
          naviAlpha = 0;
        });
      } else if (offset < 50) {
        setState(() {
          naviAlpha = 1 - (50 - offset) / 50;
        });
      } else if (naviAlpha != 1) {
        setState(() {
          naviAlpha = 1;
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.yellow,
        body: Stack(
          children: <Widget>[
            Container(
              margin: EdgeInsets.only(top: 80),//外边距
              height: Screen.height(context),
              color: Colors.grey[100],
            ),
            ListView(
              controller: _scrollController,
              children: <Widget>[
                mineHeader(),
                SizedBox(height: 10,),
                mineSell(),
                SizedBox(height: 10,),
                mineBuy(),
                SizedBox(height: 10,),
                //minePlay(),
                SizedBox(height: 10,),
              ],
            ),

            mineNavibar(naviAlpha),
          ],
        )
    );
  }
}
